<template>
    <div class="wrapperDiv">
        <Piechart ref="PiechartDiv" :piechartData="piechartData"/>
        <MyTable :tableData="tableDatacurr"/>
        <!-- <MyTable :tableData="tableDatahist"/> -->
    </div>
</template>
<script>
    import Piechart from './Piechart.vue'
    import MyTable from './Table.vue'

    export default{
        components:{Piechart,MyTable},
        name:'Demo',
        data(){
            return{
                piechartData:{
                    chartData: [
                    {name:"现金管理类",value:"4908000"},
                    {name:"固定收益类",value:"5000000"},
                    {name:"权益类",value:"3000000"},
                    {name:"保险类",value:"4000000"},
                    {name:"其它类",value:"6000000"}
                    ],
                    legends:['现金管理类',"固定收益类","权益类","保险类","其它类"]            
                },
                tableDatacurr:[],
                tableDatahist:[],
            }
        },
        methods:{
            loadData () {
            this.$axios({
                    method:'post',									
                    url:'http://www.xcdsystem.top:7300/mock/5f145320ceb4ef000fa2245c/xcd-client-mft/mft/queryAssetAllocation',
                    data:{}
                }).then((res)=>{
                        console.log('cg',res)
                            if(res&&res.data.data){
                                //给饼图赋值
                                const resData=res.data.data.assetAllocation;
                                this.piechartData.chartData=resData.assetAllocationRateList;
                                this.setLengendName(resData.assetAllocationRateList);
                                //给表格赋值
                                this.tableDatahist=resData.assetAllocationProductList;
                                this.tableDatacurr=resData.assetAllocationProductList;
                                console.log('bg',this.tableDatahist)
                                this.refs.PiechartDiv.currentPie();
                            }
                        }).catch((error)=>{
                            console.log('失败',error)
                        })
            },
            setLengendName(data){
                let newArray=[];
                data.map((item)=>{
                    newArray.push(item.name);
                })
                console.log('legends',newArray);
                this.piechartData.legends=newArray;
            }

        },
        created () {
            this.loadData();
        }
    }
</script>
<style scoped>
.wrapperDiv{
    width:70%;
    margin:0 auto;
}
</style>